package org.mybatis.generator.codegen.mybatis3.xmlmapper.elements;

import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType;
import org.mybatis.generator.api.dom.xml.Attribute;
import org.mybatis.generator.api.dom.xml.TextElement;
import org.mybatis.generator.api.dom.xml.XmlElement;

/**
 * Created by Administrator on 2015/6/10.
 */
public class DynamicSQLReturnList extends
        AbstractXmlElementGenerator {
    public DynamicSQLReturnList() {
        super();
    }

    @Override
    public void addElements(XmlElement parentElement) {
        XmlElement answer = new XmlElement("select"); //$NON-NLS-1$

        answer.addAttribute(new Attribute(
                "id", "dynamicSQLReturnList")); //$NON-NLS-1$

        FullyQualifiedJavaType parameterType = introspectedTable.getRules()
                .calculateAllFieldsClass();

        answer.addAttribute(new Attribute("parameterType", //$NON-NLS-1$
                "java.lang.String"));

        answer.addAttribute(new Attribute("resultMap", introspectedTable.getBaseResultMapId()));
//        answer.addAttribute(new Attribute("resultType", parameterType.getFullyQualifiedName()));

        context.getCommentGenerator().addComment(answer);

        StringBuilder sb = new StringBuilder();

        sb.append("<![CDATA[ ${value} ]]>"); //$NON-NLS-1$
        answer.addElement(new TextElement(sb.toString()));

        parentElement.addElement(answer);
    }
}
